import { observable, action } from 'mobx';
import { WeaForm, WeaTableNew } from 'comsMobx';
import { WeaLocaleProvider } from 'ecCom';

import * as API_REPORT from '../../apis/reportApi';

const { TableStore } = WeaTableNew;
const getLabel = WeaLocaleProvider.getLabel;

/**
 * 公文报表对话框  数据对象
 */
export default class ReportFlowDetailListDialogStore {
  @observable S_BUTTON = {
    NAME_RESET: getLabel(27088, '重置'),
    NAME_SEARCH: getLabel(82529, '搜索'),
    NAME_CANCEL: getLabel(31129, '取消'),
  }

  @observable visable = false;
  @observable loading = true;

  // 是否显示高级搜索面板
  @observable showSearchAd = false;

  @observable condition_base = {};
  @observable condition_status = '';
  @observable condition_key = '';

  // 搜索条件
  @observable searchCondition = [];

  @observable form = new WeaForm();

  @observable tableStore = new TableStore();
  @observable dataKey = ''
  constructor() {
    this.doSearch = this.doSearch.bind(this);
  }


  @action
  setSearchCondition = (searchCondition) => {
    this.searchCondition = searchCondition;
  }

  @action
  getFormParams () {
    return this.form.getFormParams();
  }

  setCondition_base = (condition_base) => {
    this.condition_base = condition_base;
  }

  // 高级搜索面板隐藏和显示切换
  changeShowSearchAd (b) {
    this.showSearchAd = b;
  }


  doSearch (params = {}) {
    // params = this.getFormParams();
    this.loading = true;
    API_REPORT.getOdocReportDetailList(params).then((data) => {
      this.tableStore.getDatas(data.sessionkey, params.current || 1);
      this.dataKey = data.sessionkeyNoUser;
      this.loading = false;
      this.showSearchAd = false;
    });
    return this;
  }

  // 构建搜索条件
  buildSearchCondition (params = {}) {
    API_REPORT.getOdocReportDetailCondition(params).then((data) => {
      this.setSearchCondition(data);
      const conditioninfo = data.conditions || data.condition;
      this.form.initFormFields(conditioninfo);
    });
  }

  getSearchsBaseValue () {
    return this.form.getFormParams().requestname;
  }

  setSearchsBaseValue (v) {
    this.form.updateFields({
      requestname: {
        value: v,
      },
    });
  }

  showDialog (status, key) {
    this.condition_status = status;
    this.condition_key = key;
    // this.doSearch();
    this.visable = true;
  }

  hideDialog = () => {
    this.visable = false;
  }
}
